package com.binvshe.binvshe.organization.entity;

import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;

import com.binvshe.binvshe.app.MyApplication;
import com.google.gson.annotations.SerializedName;
import com.pachong.android.frameworkbase.utils.io.SharePreferenceUtil;

/**
 * Created by Zoi.
 * E-mail：KyluZoi@gmail.com
 * 2016/9/14
 */
public class ClubEntity {

    private static final String SP_FILENAME_CLUB = ClubEntity.class.getSimpleName();
    private static final String KEY_ID = "key_id";
    private static final String KEY_USER_ID = "user_id";
    private static final String KEY_IM_GROUP_ID = "im_group_id";
    private static final String KEY_NAME = "name";
    private static final String KEY_CATID = "catid";
    private static final String KEY_PORTRAIT = "portrait";
    private static final String KEY_SIGN = "sign";
    private static final String KEY_INTRODUCTION = "introduction";
    private static final String KEY_PROVINCE = "province";
    private static final String KEY_CITY = "city";
    private static final String KEY_LONGITUDE = "longitude";
    private static final String KEY_LATITUDE = "latitude";
    private static final String KEY_NAME_PY = "name_py";
    private static final String KEY_INITIAL = "initial";
    private static final String KEY_STATE = "state";
    private static final String KEY_DEL = "del";
    private static final String KEY_CREATE_TIME = "create_time";
    private static final String KEY_UPDATE_TIME = "update_time";
    private static final String KEY_CATE_NAME = "cate_name";
    private static final String KEY_MEMBER_COUNT = "member_count";
    private static final String KEY_FANS = "fans";
    private static final String KEY_NOTE = "note";

    @SerializedName("id")
    private int mId;
    @SerializedName("user_id")
    private int mUserId;
    @SerializedName("im_group_id")
    private String mImGroupId;
    @SerializedName("name")
    private String mName;
    @SerializedName("catid")
    private int mCatid;
    @SerializedName("portrait")
    private String mPortrait="";
    @SerializedName("sign")
    private String mSign;
    @SerializedName("introduction")
    private String mIntroduction;
    @SerializedName("province")
    private String mProvince;
    @SerializedName("city")
    private String mCity;
    @SerializedName("longitude")
    private int mLongitude;
    @SerializedName("latitude")
    private int mLatitude;
    @SerializedName("name_py")
    private String mNamePy;
    @SerializedName("initial")
    private String mInitial;
    @SerializedName("state")
    private boolean mState;
    @SerializedName("del")
    private boolean mDel;
    @SerializedName("create_time")
    private String mCreateTime;
    @SerializedName("update_time")
    private String mUpdateTime;
    @SerializedName("cate_name")
    private String mCateName;
    @SerializedName("fans")
    private int mFans;
    @SerializedName("member_count")
    private int mMember_count;
    @SerializedName("leader_id")
    private int mLeaderID;
    @SerializedName("note")
    private String mNote;//公告

    public static ClubEntity createFromSp() {
        ClubEntity clubEntity = new ClubEntity();

        clubEntity.setId(getInt(KEY_ID));
        clubEntity.setIm_group_id(getString(KEY_IM_GROUP_ID));
        clubEntity.setName(getString(KEY_NAME));
        clubEntity.setCatid(getInt(KEY_CATID));
        clubEntity.setPortrait(getString(KEY_PORTRAIT));
        clubEntity.setSign(getString(KEY_SIGN));
        clubEntity.setIntroduction(getString(KEY_INTRODUCTION));
        clubEntity.setProvince(getString(KEY_PROVINCE));
        clubEntity.setCity(getString(KEY_CITY));
        clubEntity.setLongitude(getInt(KEY_LONGITUDE));
        clubEntity.setLatitude(getInt(KEY_LATITUDE));
        clubEntity.setName_py(getString(KEY_NAME_PY));
        clubEntity.setInitial(getString(KEY_INITIAL));
        clubEntity.setState(getBoolean(KEY_STATE));
        clubEntity.setDel(getBoolean(KEY_DEL));
        clubEntity.setCreate_time(getString(KEY_CREATE_TIME));
        clubEntity.setUpdate_time(getString(KEY_UPDATE_TIME));
        clubEntity.setCate_name(getString(KEY_CATE_NAME));
        clubEntity.setFans(getInt(KEY_FANS));
        clubEntity.setMember_count(getInt(KEY_MEMBER_COUNT));
        clubEntity.setNote(getString(KEY_NOTE));
        return clubEntity;
    }

    public static ClubEntity createFrom(ClubEntity club) {
        ClubEntity clubEntity = new ClubEntity();
        clubEntity.setId(club.getId());
        clubEntity.setIm_group_id(club.getIm_group_id());
        clubEntity.setName(club.getName());
        clubEntity.setCatid(club.getCatid());
        clubEntity.setPortrait(club.getPortrait());
        clubEntity.setSign(club.getSign());
        clubEntity.setIntroduction(club.getIntroduction());
        clubEntity.setProvince(club.getProvince());
        clubEntity.setCity(club.getCity());
        clubEntity.setLongitude(club.getLongitude());
        clubEntity.setLatitude(club.getLatitude());
        clubEntity.setName_py(club.getName_py());
        clubEntity.setInitial(club.getInitial());
        clubEntity.setState(club.isState());
        clubEntity.setDel(club.isDel());
        clubEntity.setCreate_time(club.getCreate_time());
        clubEntity.setUpdate_time(club.getUpdate_time());
        clubEntity.setCate_name(club.getCate_name());
        clubEntity.setFans(club.getFans());
        clubEntity.setMember_count(club.getMember_count());
        clubEntity.setNote(club.getNote());
        return clubEntity;
    }

    public int getId() {
        return mId;
    }

    public void setId(int id) {
        if (mId != id) {
            this.mId = id;
            saveInt(KEY_ID, mId);
        }
    }

    public int getUser_id() {
        return mUserId;
    }

    public void setUser_id(int user_id) {
        if (mUserId != user_id) {
            this.mUserId = user_id;
            saveInt(KEY_USER_ID, user_id);
        }
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        if (!TextUtils.equals(mName, name)) {
            this.mName = name;
            saveString(KEY_NAME, mName);
        }
    }

    public int getCatid() {
        return mCatid;
    }

    public void setCatid(int catid) {
        if (mCatid != catid) {
            this.mCatid = catid;
            saveInt(KEY_CATID, mCatid);
        }
    }

    public String getPortrait() {
        return mPortrait;
    }

    public void setPortrait(String portrait) {
        if (!TextUtils.equals(mPortrait, portrait)) {
            this.mPortrait = portrait;
            saveString(KEY_PORTRAIT, mPortrait);
        }
    }

    public String getSign() {
        return mSign;
    }

    public void setSign(String sign) {
        if (!TextUtils.equals(mSign, sign)) {
            this.mSign = sign;
            saveString(KEY_SIGN, mSign);
        }
    }

    public String getIntroduction() {
        return mIntroduction;
    }

    public void setIntroduction(String introduction) {
        if (!TextUtils.equals(mIntroduction, introduction)) {
            this.mIntroduction = introduction;
            saveString(KEY_INTRODUCTION, mIntroduction);
        }
    }

    public String getProvince() {
        return mProvince;
    }

    public void setProvince(String province) {
        if (!TextUtils.equals(mProvince, province)) {
            this.mProvince = province;
            saveString(KEY_PROVINCE, mProvince);
        }
    }

    public String getCity() {
        return mCity;
    }

    public void setCity(String city) {
        if (!TextUtils.equals(mCity, city)) {
            this.mCity = city;
            saveString(KEY_CITY, mCity);
        }
    }

    public int getLongitude() {
        return mLongitude;
    }

    public void setLongitude(int longitude) {
        if (mLongitude != longitude) {
            this.mLongitude = longitude;
            saveInt(KEY_LONGITUDE, mLongitude);
        }
    }

    public int getLatitude() {
        return mLatitude;
    }

    public void setLatitude(int latitude) {
        if (mLatitude != latitude) {
            this.mLatitude = latitude;
            saveInt(KEY_LATITUDE, mLatitude);
        }
    }

    public String getName_py() {
        return mNamePy;
    }

    public void setName_py(String name_py) {
        if (!TextUtils.equals(mNamePy, name_py)) {
            this.mNamePy = name_py;
            saveString(KEY_NAME_PY, mNamePy);
        }
    }

    public String getInitial() {
        return mInitial;
    }

    public void setInitial(String initial) {
        if (!TextUtils.equals(mInitial, initial)) {
            this.mInitial = initial;
            saveString(KEY_INITIAL, mInitial);
        }
    }

    public boolean isState() {
        return mState;
    }

    public void setState(boolean state) {
        if (mState != state) {
            this.mState = state;
            saveBoolean(KEY_STATE, mState);
        }
    }

    public boolean isDel() {
        return mDel;
    }

    public void setDel(boolean del) {
        if (mDel != del) {
            this.mDel = del;
            saveBoolean(KEY_DEL, mDel);
        }
    }

    public String getCreate_time() {
        return mCreateTime;
    }

    public void setCreate_time(String create_time) {
        if (!TextUtils.equals(mCreateTime, create_time)) {
            this.mCreateTime = create_time;
            saveString(KEY_CREATE_TIME, mCreateTime);
        }
    }

    public String getUpdate_time() {
        return mUpdateTime;
    }

    public void setUpdate_time(String update_time) {
        if (!TextUtils.equals(mUpdateTime, update_time)) {
            this.mUpdateTime = update_time;
            saveString(KEY_UPDATE_TIME, mUpdateTime);
        }
    }

    public String getCate_name() {
        return mCateName;
    }

    public void setCate_name(String cate_name) {
        if (!TextUtils.equals(mCateName, cate_name)) {
            saveString(KEY_CATE_NAME, mCateName);
            this.mCateName = cate_name;
        }
    }

    public String getNote() {
        return mNote;
    }

    public void setNote(String note) {
        if (!TextUtils.equals(mNote, note)) {
            this.mNote = note;
            saveString(KEY_NOTE, mNote);
        }
    }

    public String getIm_group_id() {
        return mImGroupId;
    }

    public void setIm_group_id(String im_group_id) {
        if (mImGroupId != im_group_id) {
            this.mImGroupId = im_group_id;
            saveString(KEY_IM_GROUP_ID, mImGroupId);
        }
    }

    public int getFans() {
        return mFans;
    }

    public void setFans(int fans) {
        if (mFans != fans) {
            this.mFans = fans;
            saveInt(KEY_FANS, mFans);
        }
    }

    public int getMember_count() {
        return mMember_count;
    }

    public void setMember_count(int member_count) {
        if (mMember_count != member_count) {
            this.mMember_count = member_count;
            saveInt(KEY_MEMBER_COUNT, mMember_count);
        }
    }

    public int getLeaderID() {
        return mLeaderID;
    }

    public void setLeaderID(int leaderID) {
        mLeaderID = leaderID;
    }

    @Override
    public String toString() {
        return "ClubEntity{" +
                "mId=" + mId +
                ", mUserId=" + mUserId +
                ", mImGroupId='" + mImGroupId + '\'' +
                ", mName='" + mName + '\'' +
                ", mCatid=" + mCatid +
                ", mPortrait='" + mPortrait + '\'' +
                ", mSign='" + mSign + '\'' +
                ", mIntroduction='" + mIntroduction + '\'' +
                ", mProvince='" + mProvince + '\'' +
                ", mCity='" + mCity + '\'' +
                ", mLongitude=" + mLongitude +
                ", mLatitude=" + mLatitude +
                ", mNamePy='" + mNamePy + '\'' +
                ", mInitial='" + mInitial + '\'' +
                ", mState=" + mState +
                ", mDel=" + mDel +
                ", mCreateTime='" + mCreateTime + '\'' +
                ", mUpdateTime='" + mUpdateTime + '\'' +
                ", mCateName='" + mCateName + '\'' +
                ", mFans='" + mFans + '\'' +
                ", mMember_count='" + mMember_count + '\'' +
                '}';
    }

    private static void saveInt(String key, int value) {
        SharePreferenceUtil.saveInt(MyApplication.getAppContext(), SP_FILENAME_CLUB, key, value);
    }

    private static int getInt(String key) {
        return SharePreferenceUtil.getInt(MyApplication.getAppContext(), SP_FILENAME_CLUB, key);
    }

    private static void saveString(String key, String value) {
        SharePreferenceUtil.saveString(MyApplication.getAppContext(), SP_FILENAME_CLUB, key, value);
    }

    private static String getString(String key) {
        return SharePreferenceUtil.getString(MyApplication.getAppContext(), SP_FILENAME_CLUB, key);
    }

    private static void saveBoolean(String key, Boolean value) {
        SharePreferenceUtil.saveBoolean(MyApplication.getAppContext(), SP_FILENAME_CLUB, key, value);
    }

    private static Boolean getBoolean(String key) {
        return SharePreferenceUtil.getBoolean(MyApplication.getAppContext(), SP_FILENAME_CLUB, key, false);
    }

}
